#include "playsence.h"
#include<QDebug>
#include<QMenuBar>
#include<QPainter>
#include<QLabel>
#include<mytz.h>
#include"dataconfig.h"
//playsence::playsence(QWidget *parent) : QMainWindow(parent)
//{

//}
playsence::playsence(int levelNum){
    QString str=QString("进入了第%1关").arg(levelNum);
    qDebug()<<str;
    this->levenIndex=levelNum;
   this->setFixedSize(400,688);
    setWindowIcon(QIcon(":/2tb.jpg"));
    setWindowTitle("playing");
    //开始退出
    QMenuBar*bar=menuBar();
    setMenuBar(bar);
    QMenu*startmenu=bar->addMenu("开始");
    QAction*quitaction=startmenu->addAction("退出");
    connect(quitaction,&QAction::triggered,[=](){
//        this->close();
    });
    dataConfig config;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            this->gamearray[i][j]=config.mData[this->levenIndex][i][j];
        }
    }
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++){
            QLabel*label=new QLabel;
            label->setPixmap(QPixmap(":/yy.jfif"));
            label->setFixedSize(70,70);
            label->setParent(this);
            label->move(57+i*80,200+j*80);
            //创建金币
            QString str;
            if(this->gamearray[i][j]==1){
                //显示金币
                str=":/jtz1.jpg";
            }
            else{
                 str=":/jtz2.jpg";
            }
            mytz*tz=new mytz(str);

            tz->setParent(this);
            tz->move(75+i*80,220+j*80);
            //给团子赋值
            tz->posx=i;
            tz->posy=j;
            tz->flag=this->gamearray[i][j];
            tzbtn[i][j]=tz;
            //点击金币，进行翻转
            connect(tz,&mytz::clicked,[=](){
                tz->changeflag();
            //反转周围金币
                if(tz->posx+1<=3){
                    tzbtn[tz->posx+1][tz->posy]->changeflag();
                }
                if(tz->posx-1>=0){
                    tzbtn[tz->posx-1][tz->posy]->changeflag();
                }
                if(tz->posy+1<=3){
                    tzbtn[tz->posx][tz->posy+1]->changeflag();
                }
                if(tz->posy-1>=0){
                    tzbtn[tz->posx][tz->posy-1]->changeflag();
                }

            });

        }
    }




}
void playsence::paintEvent(QPaintEvent*){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/bj2.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);//金币背景

}
